<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="货主编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shipperCode']" placeholder="请输入货主编码"></a-input>
        </a-form-item>
        <a-form-item label="货主名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shipperName']" placeholder="请输入货主名称"></a-input>
        </a-form-item>
        <a-form-item label="客户组" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['clientGroup']" placeholder="请输入客户组"></a-input>
        </a-form-item>
        <a-form-item label="外文名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['englishName']" placeholder="请输入外文名称"></a-input>
        </a-form-item>
        <a-form-item label="客户属性" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['clientAttribute']" placeholder="请输入客户属性"></a-input>
        </a-form-item>
        <a-form-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['address']" placeholder="请输入地址"></a-input>
        </a-form-item>
        <a-form-item label="负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['principal']" placeholder="请输入负责人"></a-input>
        </a-form-item>
        <a-form-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['phone']" placeholder="请输入电话"></a-input>
        </a-form-item>
        <a-form-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['contactPerson']" placeholder="请输入联系人"></a-input>
        </a-form-item>
        <a-form-item label="联系人电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['contactPhone']" placeholder="请输入联系人电话"></a-input>
        </a-form-item>
        <a-form-item label="手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['mobilePhone']" placeholder="请输入手机"></a-input>
        </a-form-item>
        <a-form-item label="Email地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['emailAddress']" placeholder="请输入Email地址"></a-input>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['notes']" placeholder="请输入备注"></a-input>
        </a-form-item>
        <a-form-item label="社会信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['socialCode']" placeholder="请输入社会信用代码"></a-input>
        </a-form-item>
        <a-form-item label="开票地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['drawAddress']" placeholder="请输入开票地址"></a-input>
        </a-form-item>
        <a-form-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['openBank']" placeholder="请输入开户银行"></a-input>
        </a-form-item>
        <a-form-item label="银行账号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['bankAccount']" placeholder="请输入银行账号"></a-input>
        </a-form-item>
        <a-form-item label="信用额度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['creditLimits']" placeholder="请输入信用额度"></a-input>
        </a-form-item>
        <a-form-item label="付款条款" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['payItem']" placeholder="请输入付款条款"></a-input>
        </a-form-item>
        <a-form-item label="未清出货金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['overdueMoney']" placeholder="请输入未清出货金额"></a-input>
        </a-form-item>
        <a-form-item label="应收余额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['receiveableMoney']" placeholder="请输入应收余额"></a-input>
        </a-form-item>
        <a-form-item label="上级渠道" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['superiorChannel']" placeholder="请输入上级渠道"></a-input>
        </a-form-item>
        <a-form-item label="上级公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['superiorCompany']" placeholder="请输入上级公司"></a-input>
        </a-form-item>
        <a-form-item label="税率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['taxRate']" placeholder="请输入税率"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  
  export default {
    name: "MesChiefdataShipperModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/chiefdata/mesChiefdataShipper/add",
          edit: "/chiefdata/mesChiefdataShipper/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'shipperCode','shipperName','clientGroup','englishName','clientAttribute','address','principal','phone','contactPerson','contactPhone','mobilePhone','emailAddress','notes','socialCode','drawAddress','openBank','bankAccount','creditLimits','payItem','overdueMoney','receiveableMoney','superiorChannel','superiorCompany','taxRate'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'shipperCode','shipperName','clientGroup','englishName','clientAttribute','address','principal','phone','contactPerson','contactPhone','mobilePhone','emailAddress','notes','socialCode','drawAddress','openBank','bankAccount','creditLimits','payItem','overdueMoney','receiveableMoney','superiorChannel','superiorCompany','taxRate'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>